/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dom.workflow;

import dom.Command;
import dom.StreamFactory;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

/**
 *
 * @author julian.pena
 */
public class WorkFlowHelper {
    
    public static void connectCommands(Command c1, Command c2) throws Exception{
        boolean c1Ready = c1.isOutputReady();
        boolean c2Ready = c2.isInputReady();
        if (!c1Ready && !c2Ready) {
            PipedInputStream in = StreamFactory.getPipedInputStream();
            PipedOutputStream out = StreamFactory.getPipedOutputStream();
            StreamFactory.connect(in, out);
            c1.setOutputStream(out);
            c2.setInputStream(in);
        } else if (c1Ready && c2Ready){
            return;
        } else {
            throw new Exception("Comandos no compatibles");
        }
        
    }
    
}
